<?php

namespace app\adminapi\export;

use app\model\activity\seckill\StoreSeckillProduct;
use app\services\activity\seckill\StoreSeckillServices;
use Carbon\Carbon;

class StoreSeckillExport extends BaseExport
{
    protected $header = [
        '活动名称', '有效时间', '状态', '订单实付金额(元)', '付款订单数', '付款人数', '活动开启/关闭'
    ];

    public function createData(array $where)
    {
        $list = app()->make(StoreSeckillServices::class)->systemPage($where)['list'];
        $data = [];

        $time_status_map = [
            0   =>  '未开始',
            1   =>  '进行中',
            2   =>  '已结束'
        ];

        $status_map = [
            0 =>    '关闭',
            1 =>    '开启'
        ];

        foreach ($list as $item) {

            $expire_time = ($item['start_time'] && $item['end_time']) ? Carbon::parse($item['start_time'])->format('Y-m-d H:i:s') . '至' . Carbon::parse($item['end_time'])->format('Y-m-d H:i:s') : '';

            $data[] = [
                $item['title'] ?? '',
                $expire_time,
                $time_status_map[$item['time_status']] ?? '',
                $item['total_order_amount'] ?? '',
                $item['has_pay_order_nums'] ?? '',
                $item['has_pay_order_person_num'] ?? '',
                $status_map[$item['status']] ?? ''
            ];
        }

        return $data;
    }
}